import Vue from 'vue'
import VueRouter from 'vue-router'
import {home,showlist,error404,main,login} from "@/view"
Vue.use(VueRouter)
const router= new VueRouter({
    routes:[{
      path:"/",
      component:main,
      children:[
        {
          path:"",
          component:home,
          meta:{title:"首页",index:"0"}
        },{
          path:"/showlist",
          component:showlist,
          meta:{title:"用户列表",index:"1-1"}
        }
      ]
    },{
      path:"*",
      component:error404
  },{
    path:"/login",
    component:login,
    meta:{title:"登录"}
  }]
  })
  export default router
  router.beforeEach((to, from, next) => {
    // console.log(to.fullPath)
    if(to.meta && to.meta.title){
      document.title = to.meta.title
    }
    if(to.fullPath!=="/login"){
      if(!sessionStorage.getItem("loginuser"))
      return next("/login")
    }
    next()
    // console.log(next(""))
  })